<?php

namespace Admin\Controller;

class ReportController extends CommonController
{
    // 举报列表
    public function lists()
    {
        $type     = I("request.type", '', 'trim');
        $audit    = I('request.audit', '', 'trim');
        $key      = I('get.key', '', 'trim');
        $key_type = I('get.key_type', '', 'intval');
        $page     = true;
        $sort     = 'id desc';
        $num      = 10;

        $map = array();
        if ($type) {
            $map['type'] = $type;
        }
        if ($audit != '') {
            $map['audit'] = $audit;
        }
        if ($key != '') {
            if ($key_type == 1) {
                $map['content'] = array('like', '%' . $key . '%');
            } elseif ($key_type == 2) {
                $map['uid'] = $key;
            }
        }
        $lists = D('Report')->get_list($map, $page, $sort, $num, true);
        $this->assign('lists', $lists);

        $this->display();
    }

    // 举报审核
    public function audit()
    {
        $ids   = I('post.id');
        $audit = I('post.audit', '0', 'trim');

        $ids = is_array($ids) ? implode(',', $ids) : $ids;
        if ($ids && is_match_ids($ids)) {
            D('Report')->report_audit($audit, $ids);
            $this->success('设置成功');
        } else {
            $this->error('请选择条目');
        }
    }

    // Ajax举报详情
    public function ajax_report_show()
    {
        $id   = I("request.id", '', 'intval');
        $info = D('Report')->get_report_one($id);
        $this->assign('info', $info);
        $html           = $this->fetch();
        $ret['status']  = 1;
        $ret['content'] = $html;

        $this->ajaxReturn($ret);
    }

    // 删除举报
    public function delete()
    {
        $ids = I('param.id', '', 'trim');

        $ids = is_array($ids) ? implode(',', $ids) : $ids;
        if ($ids && is_match_ids($ids)) {
            D('Report')->report_del($ids);
            $this->success('操作成功');
        } else {
            $this->error('请选择条目');
        }
    }
}